package com.dragon.repository.mapper;

import com.dragon.repository.entity.RequisitionProduct;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.scheduling.annotation.Scheduled;

import java.util.List;

/**
 * <p>
 * 请购的物品表 Mapper 接口
 * </p>
 *
 * @author sy
 * @since 2023-10-20
 */
@Mapper
public interface RequisitionProductMapper extends BaseMapper<RequisitionProduct> {

    @Select("<script>" +
            "SELECT M.* FROM (select a.*, aa.spu_specification as specificationName, aa.name as productName, au.name as unitName  from dragon_requisition_product a " +
            "left join dragon_product aa on a.product_spu_id = aa.id " +
            "left join dragon_product_unit au on a.unit_id = au.id )M WHERE 1=1 and M.requisition_id = #{id} " +
            "<if test='generateState != null and generateState != \"\"'> "+
            " and M.product_state = #{generateState} " +
            "</if> " +
            "</script>")
    List<RequisitionProduct> selectByRequisitionId(Integer id, Integer generateState);

    @Select("SELECT M.* FROM (select a.*, aa.spu_specification as specificationName, aa.name as productName, au.name as unitName  from dragon_requisition_product a " +
            "left join dragon_product aa on a.product_spu_id = aa.id " +
            "left join dragon_product_unit au on a.unit_id = au.id )M WHERE 1=1 and M.id = #{id} " )
   RequisitionProduct selectOneDeteilById(Integer id);

}
